package com.example.study_thread.b_iterator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class Demo1Iterator {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");

//        注意iterator使用时，不要连续多次使用
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        
        HashSet<Object> set = new HashSet<>();
        Iterator<Object> iterator1 = set.iterator();
    }
}
